package com.ayoka.ui.main;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;

import com.ayoka.R;
import com.ayoka.adapter.TrainingPackageAdapter;
import com.ayoka.base.BaseRecyclerViewFragment;
import com.ayoka.bean.TrainingPackageBean;
import com.ayoka.databinding.FragmentMeditationBinding;
import com.ayoka.mvp.DoMVP.DoPresenter;
import com.ayoka.mvp.DoMVP.IDoView;
import com.ayoka.ui.training.TrainingGroupActivity;
import com.jcp.baselibrary.brvah.BaseQuickAdapter;
import com.jcp.baselibrary.brvah.BaseViewHolder;
import com.jcp.baselibrary.brvah.RecycleViewDivider;
import com.jcp.baselibrary.utils.UIUtils;

import java.util.List;

/**
 * 做到的Fragment
 * <p>
 * Created by admin on 2017/3/22.
 */

public class MeditationFragment extends BaseRecyclerViewFragment<TrainingPackageBean, FragmentMeditationBinding, DoPresenter> implements IDoView {

    @Override
    public int getContentLayout() {
        return R.layout.fragment_meditation;
    }

    @Override
    protected SwipeRefreshLayout getRefreshLayout() {
        return mDataBinding.swipeRefresh;
    }

    @Override
    protected RecyclerView getRecyclerView() {
        return mDataBinding.recyclerView;
    }

    @NonNull
    @Override
    protected BaseQuickAdapter<TrainingPackageBean, ? extends BaseViewHolder> getAdapter() {
        TrainingPackageAdapter adapter = new TrainingPackageAdapter();
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                TrainingPackageBean trainingPackageBean = (TrainingPackageBean) adapter.getItem(position);
                TrainingGroupActivity.start(getActivity(), 0, trainingPackageBean.ID);
            }
        });
        return adapter;
    }

    @Override
    protected RecyclerView.ItemDecoration getRecycleDivider() {
        return new RecycleViewDivider.Builder(getActivity())
                .setStyle(RecycleViewDivider.Style.BOTH)
                .setColor(Color.TRANSPARENT)
                .setSize(TypedValue.COMPLEX_UNIT_PX, UIUtils.getDimensionPixelSize(R.dimen.dp_20))
                .build();
    }

    @Override
    protected void getData(boolean isShowWaitDialog) {
        mPresenter.getTrainingPackageListData(isShowWaitDialog);
    }

    @Override
    public void initData() {
        getData(true);
    }

    @Override
    protected DoPresenter getPresenter() {
        return new DoPresenter();
    }


    @Override
    public void configTrainingPackageListData(List<TrainingPackageBean> listData) {
        setLoadMoreLayout(listData);
    }
}
